//
//  ViewController.swift
//  SHMediaTools
//
//  Created by weishihao on 06/21/2023.
//  Copyright (c) 2023 weishihao. All rights reserved.
//

import UIKit

class ViewController: UIViewController {
    
//    let vc1 = CaptureViewController();
    
    private let vcDic: [String: UIViewController] = [
        "CaptureViewController": CaptureViewController(),
        "CaptureViewController2": CaptureViewController(),
        "CaptureViewController3": CaptureViewController(),
    ]
    
//    var vcDic =  [String: UIViewController]()
    
//    var vcDic:[String:AnyClass] = ["CaptureViewController":vc1]
    

    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        self.view.backgroundColor = .yellow
        
        let btnH = 70
        var i = 0;
        
        for vcName in vcDic.keys {
            let btn: UIButton = UIButton(type: .roundedRect);
            self.view.addSubview(btn)
            
            btn.frame = CGRect(x: 20, y: (i * (btnH + 10)) + 60, width: 200, height: btnH);
            btn.setTitle(vcName, for: .normal)
            btn.backgroundColor = randomColor()
            btn.addTarget(self, action: #selector(btnEvent), for: .touchUpInside)
            
            btn.tag = i
            i += 1
        }
    }
    
    func randomColor() -> UIColor {
        let color = UIColor(red: self.randomNum(), green: self.randomNum(), blue: self.randomNum(), alpha: 1)
        return color
    }
    
    func randomNum() -> CGFloat {
        let randomNum = CGFloat(arc4random_uniform(255)) / 255.0
        return randomNum
    }
    
    @objc func btnEvent(btn: UIButton) -> Void {
        let vc = Array(vcDic.values)[btn.tag]
        self.navigationController?.pushViewController(vc, animated: true)
    }
    
    

    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }

}

